﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CSharpHW1
{
    public partial class Form1 : Form
    {
        string num1;
        string num2;
        string opera;
        public Form1()
        {
            InitializeComponent();
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            opera = comboBox1.Text;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            num1 = textBox1.Text;
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            num2 = textBox2.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(num1 == null || num2 == null || num1 == "请输入数值" || num2 == "请输入数值")
            {
                textBox1.Text = "请输入数值";
                textBox2.Text = "请输入数值";
                return;
            }
            double n1 = Double.Parse(num1);
            double res=0;
            double n2 = Double.Parse(num2);
            switch (opera)
            {
                case "+": res = n1 + n2; break;
                case "-": res = n1 - n2; break;
                case "*": res = n1 * n2; break;
                case "/": res = n1 / n2; break;
                default: textBox3.Text = "错误运算"; return;
            }
            textBox3.Text = res.ToString("0.000");
        }
    }
}
